package com.easyadmin.modules.stock.controller;

import com.easyadmin.common.aop.annotation.Repeat;
import com.easyadmin.common.web.base.BaseController;
import com.easyadmin.common.web.domain.request.PageDomain;
import com.easyadmin.common.web.domain.response.Result;
import com.easyadmin.common.web.domain.response.module.ResultTable;
import com.easyadmin.modules.stock.domain.SysStockImps;
import com.easyadmin.modules.stock.service.ISysStockImpsService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * 即时通信Controller
 *
 * @author jmys
 * @date 2025-10-02
 */
@RestController
@RequestMapping("/stock/stockImps")
public class SysStockImpsController extends BaseController {

    private String prefix = "stock/stockImps";

    @Autowired
    private ISysStockImpsService sysStockImpsService;

    @GetMapping("/main")
    @PreAuthorize("hasPermission('/stock/stockImps/main','stock:stockImps:main')")
    public ModelAndView main() {
        return jumpPage(prefix + "/main");
    }

    /**
     * 查询即时通信列表
     */
    @GetMapping("/data")
    @ApiOperation(value = "查询即时通信列表")
    @PreAuthorize("hasPermission('/stock/stockImps/data','stock:stockImps:data')")
    public ResultTable list(@ModelAttribute SysStockImps sysStockImps, PageDomain pageDomain) {
        PageInfo<SysStockImps> pageInfo = sysStockImpsService.selectSysStockImpsPage(sysStockImps, pageDomain);
        return pageTable(pageInfo.getList(), pageInfo.getTotal());
    }

    /**
     * 新增即时通信
     */
    @GetMapping("/add")
    @PreAuthorize("hasPermission('/stock/stockImps/add','stock:stockImps:add')")
    public ModelAndView add() {
        return jumpPage(prefix + "/add");
    }

    /**
     * 新增即时通信
     */
    @Repeat
    @PostMapping("/save")
    @ApiOperation(value = "新增即时通信")
    @PreAuthorize("hasPermission('/stock/stockImps/add','stock:stockImps:add')")
    public Result save(@RequestBody SysStockImps sysStockImps) {
        return decide(sysStockImpsService.save(sysStockImps));
    }

    /**
     * 修改即时通信
     */
    @GetMapping("/edit")
    @PreAuthorize("hasPermission('/stock/stockImps/edit','stock:stockImps:edit')")
    public ModelAndView edit(Long id, ModelMap map) {
        SysStockImps sysStockImps =sysStockImpsService.getById(id);
        map.put("sysStockImps", sysStockImps);
        return jumpPage(prefix + "/edit");
    }

    /**
     * 修改即时通信
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改即时通信")
    @PreAuthorize("hasPermission('/stock/stockImps/edit','stock:stockImps:edit')")
    public Result update(@RequestBody SysStockImps sysStockImps) {
        return decide(sysStockImpsService.update(sysStockImps));
    }

    /**
     * 删除即时通信
     */
    @DeleteMapping("/batchRemove")
    @ApiOperation(value = "删除即时通信")
    @PreAuthorize("hasPermission('/stock/stockImps/remove','stock:stockImps:remove')")
    public Result batchRemove(String ids) {
        return decide(sysStockImpsService.batchRemove(ids.split(",")));
    }

    /**
     * 删除即时通信
     */
    @DeleteMapping("/remove/{id}")
    @ApiOperation(value = "删除即时通信")
    @PreAuthorize("hasPermission('/stock/stockImps/remove','stock:stockImps:remove')")
    public Result remove(@PathVariable("id") Long id) {
        return decide(sysStockImpsService.remove(id));
    }
}
